import request from '@/axios'
import type {
  AdvertPositionListParams,
  AdvertPositionListResponse,
  AdvertPositionDetailResponse,
  AdvertPositionCreateOrUpdateParams
} from '../types'

// 获取广告位列表
export const getAdvertPositionPageList = (
  params: AdvertPositionListParams
): Promise<AdvertPositionListResponse> => {
  return request.get({ url: '/advertPosition/list', params }).then(res => {
    return {
      code: res.code,
      message: res.data?.message || '',
      data: res.data
    } as AdvertPositionListResponse
  })
}

// 获取广告位详情
export const getAdvertPositionDetail = (id: number): Promise<AdvertPositionDetailResponse> => {
  return request.get({ url: `/advertPosition/${id}` }).then(res => {
    return {
      code: res.code,
      message: res.data?.message || '',
      data: res.data
    } as AdvertPositionDetailResponse
  })
}

// 创建广告位
export const createAdvertPosition = (
  data: AdvertPositionCreateOrUpdateParams
): Promise<IResponse> => {
  return request.post({ url: '/advertPosition/create', data })
}

// 更新广告位
export const updateAdvertPosition = (
  id: number,
  data: AdvertPositionCreateOrUpdateParams
): Promise<IResponse> => {
  return request.put({ url: `/advertPosition/update/${id}`, data })
}

// 删除广告位
export const deleteAdvertPosition = (id: number): Promise<IResponse> => {
  return request.delete({ url: `/advertPosition/delete/${id}` })
}